import mysql.connector
import configparser
from PIL import Image
import random
import string

def create_db_connection():
    config = configparser.ConfigParser()
    config.read('config.cfg')
    database_config = config['database']

    # 配置数据库连接
    conn = mysql.connector.connect(
        host=database_config.get('host'),
        user=database_config.get('user'),
        password=database_config.get('password'),
        database=database_config.get('database')
    )

    cursor = conn.cursor()
    return conn, cursor

def generate_random_string():
    length = random.randint(8, 15)
    all_characters = string.digits + string.ascii_letters
    random_string = ''.join(random.choice(all_characters) for i in range(length))
    return random_string